<%@ page import="org.biojava.services.das.dao.RegistryUser" %>
<%@ page import="org.biojava.services.das.registry.UserManager" %>
<%@ page import="org.biojava.services.das.dao.Role" %>
<%@ page import="java.util.Date" %>
<jsp:directive.page import="org.biojava.services.das.registry.DasRegistrySql" />
<jsp:directive.page import="org.biojava.dasobert.dasregistry.DasSource" />
<jsp:directive.page	import="org.biojava.dasobert.dasregistry.DasSourceComparator" />
<jsp:directive.page import="java.util.Comparator" />
<jsp:directive.page import="org.springframework.beans.factory.BeanFactory"/>
<jsp:directive.page import="org.springframework.context.support.ClassPathXmlApplicationContext"/>
<jsp:directive.page import="java.util.List"/>
<% String title="broken DAS servers";
   String header=title;
%>

<%@ include file="sangerheader.jsp" %>

<%  if  ( ! isAdmin ) {
	session.setAttribute("message","only administrators can view this page");
	response.sendRedirect("login.jsp");	
	return;
} else { 
	
	BeanFactory ctx=(new ClassPathXmlApplicationContext("SpringDAO.xml"));
		DasRegistrySql registry=(DasRegistrySql)ctx.getBean("registryBean");
	
%>



<div id="main">
<h2>Broken DAS servers</h2>
<%@ include file="sangertablestart.jsp" %>
<%	
	String sort = "leasedate";
	List<DasSource> s = registry.listServices();
	Comparator dsc = DasSourceComparator.fromString(sort);
	java.util.Collections.sort(s, dsc);

	int oneday = 1000 * 60 * 60 * 24 ;
	int twodays = oneday * 2;
	Date now = new Date();
	int count = -1;	
	for (int i=0; i < s.size() ; i++){
		DasSource ds = s.get(i);
		
		if ( ds.getLeaseDate().getTime() > ( now.getTime() - twodays ) ) 
			continue;


		
		
		count++;		
		%>
		
<% if (count % 2 != 0) {
%>
<tr id="row1" valign="top">
	<%
	} else {
	%>

<tr id="row2" valign="top">
<%} %>

	<td><a href="showdetails.jsp?auto_id=<%=ds.getId() %>"><%=ds.getId() %></a></td>
	<td><%=ds.getNickname() %></td>	
	<td><%=ds.getAdminemail() %></td>
	<td><%=ds.getLeaseDate() %> (<%=((now.getTime()- ds.getLeaseDate().getTime()) / oneday) %> days)</td>
</tr>
<%} %>

<%@ include file="sangertableend.jsp" %>

Currently <%=count %> DAS sources are broken.

<%} %>		
	

<%@ include file="sangerfooter.jsp" %>
